package com.soecode.lyf.web;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.soecode.lyf.dto.Result;
import com.soecode.lyf.entity.Data;
import com.soecode.lyf.entity.User;
import com.soecode.lyf.service.LessonService;

@Controller
@RequestMapping("/data") // url:/模块/资源/{id}/细分 /seckill/list
public class LessonController {
	
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	@Autowired
	private LessonService lessonservice;
	private List<Data> list;
	private List<Data> list1;
	private List<Data> list2;
	private List<Data> list3;
	private List<Data> content;
	@ResponseBody
	@RequestMapping(value = "/lesson", method = RequestMethod.GET)
	private Result getLesson(String wiki,String subtype,String subtype1,String subtype2,String subtype3,Model model) {
		Result result = new Result();
		System.out.println("目录1"+subtype+"目录2"+subtype1+"目录3"+subtype2+"目录4"+subtype3);
		if(!StringUtils.isEmpty(wiki)&&StringUtils.isEmpty(subtype)&&StringUtils.isEmpty(subtype1)&&StringUtils.isEmpty(subtype2)&&StringUtils.isEmpty(subtype3)){// 按章节查询
			content = lessonservice.getLessonContent(wiki);
			if(content.size()==0) {
			content = lessonservice.getLessonContenCto(wiki);	
			}
			model.addAttribute("content",content);
		}
		if(subtype!=null || subtype!="") { // 目录1
			list = lessonservice.getLessonTitle(subtype);	
			System.out.println("看看"+list);
			model.addAttribute("mlname",list);
		}
		if(subtype1!=null||subtype1!="") {// 目录2
			list1 = lessonservice.getLessonTitle(subtype1);
			if(list1.size()==0) {
			list1 = lessonservice.getLessonTitleCto(subtype1);
			}
			model.addAttribute("mlname1",list1);
		}
		if(subtype2!=null||subtype2!="") {// 目录3
			list2 = lessonservice.getLessonTitle(subtype2);
			if(list2.size()==0) {
				list2 = lessonservice.getLessonTitleCto(subtype2);
				}
			model.addAttribute("mlname2",list2);
		}
		if(subtype3!=null||subtype3!="") {// 目录4
			list3 = lessonservice.getLessonTitle(subtype3);
			if(list3.size()==0) {
				list3 = lessonservice.getLessonTitleCto(subtype3);
				}
			model.addAttribute("mlname3",list3);
		}
		result = new Result(0,model,"查询成功");
		return result;
	}
}
